﻿using System.Configuration;
using Microsoft.Extensions.Configuration;
using SqlSugar;

namespace Crossroad.Core.Configs
{
    /// <summary>
    /// 应用程序配置参数
    /// </summary>
    public class AppConfig
    {
        private static string _connectionString;
        private static string _serverHost;
        private static string _iconUploadDef;
        private static string _dbType;
        private static string _autofacModules;
        private static string _originsPassHost;

        public AppConfig(IConfiguration config)
        {
            _connectionString = config.GetConnectionString("DefConnection");
            _serverHost = config["AppSettings:ServerHost"] ?? string.Empty;
            _iconUploadDef = config["AppSettings:IconUploadDef"] ?? string.Empty;
            _dbType = config["AppSettings:DbType"] ?? string.Empty;
            _autofacModules = config["AppSettings:AutofacModules"] ?? string.Empty;
            _originsPassHost = config["AppSettings:OriginsPassHost"] ?? string.Empty;
        }


        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public static string ConnectionString => _connectionString;

        /// <summary>
        /// 数据库类型
        /// </summary>
        public static DbType DbType {
            get
            {
                switch (_dbType?.ToLower())
                {
                    case var a when a.Equals("mysql"):
                        return DbType.MySql;
                }

                return DbType.SqlServer;
            }
        }

        /// <summary>
        /// 默认页大小
        /// </summary>
        public const int DEFAULT_PAGE_SIZE = 10;

        /// <summary>
        /// 服务端地址
        /// </summary>
        public static string ServerHost => _serverHost;
        /// <summary>
        /// 上传图标默认图片
        /// </summary>
        public static string IconUploadDef  => _iconUploadDef;
        /// <summary>
        /// 需要自动注入的模块
        /// </summary>
        public static string AutofacModules => _autofacModules;
        /// <summary>
        /// 跨域放过的主机域名 多个请用“,”隔开
        /// </summary>
        public static string OriginsPassHost => _originsPassHost;
    }
}
